package classes.Commands
{
	import MLP.mlp_effects;
	import components.editor.c_baseEditor;
	import components.editor.c_baseElement;
	import components.editor.c_effectElement;
	
	import flash.geom.Rectangle;
	
	public class c_insertEffectCommand extends c_commandFromEditor {
		private var _index			: int;
		public function c_insertEffectCommand(a_editor:c_baseEditor) {
			super(a_editor);
		}
		
		override public function Execute():void {
			super.Execute();
			if (!_element) {
				var link: c_baseElement = editor.dragRect.link; 
				var rect: Rectangle = link.getBounds(editor.imageLayer);
				_element = new c_effectElement(editor.imageLayer, rect.x, rect.y, rect.width, rect.height);
				
				_element.owner = link;
				asEffect.params = mlp_effects.list[mlp_effects.effectIndex(1)];
			} else _element.setParent(editor.imageLayer, _index);
			
			editor.dragRect.link = _element; 
		}
		
		public function get asEffect(): c_effectElement {
			return _element as c_effectElement;
		}
		
		override public function unExecute():void {
			_element.remove();
			super.unExecute();
		}
	}
}